package com.miplus.ccrm.core.service.strategy;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.yulichang.base.MPJBaseServiceImpl;
import com.github.yulichang.wrapper.MPJLambdaWrapper;
import com.miplus.ccrm.common.CmdResVo;
import com.miplus.ccrm.common.JPubUtils;
import com.miplus.ccrm.core.controller.vo.strategy.TriggerResVo;
import com.miplus.ccrm.core.controller.vo.strategy.TriglinkEditVo;
import com.miplus.ccrm.core.controller.vo.strategy.TriglinkReqVo;
import com.miplus.ccrm.core.controller.vo.strategy.TriglinkResVo;
import com.miplus.ccrm.core.pojo.CpCalllistTrigger;
import com.miplus.ccrm.core.pojo.CpCalllistTriggerQuerylink;
import com.miplus.ccrm.core.mapper.CpCalllistTriggerQuerylinkMapper;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import java.util.Date;

/**
* @author pc
* @description 针对表【cp_calllist_trigger_querylink(触发器规则表)】的数据库操作Service实现
* @createDate 2024-03-22 16:38:19
*/
@Service
public class CpCalllistTriggerQuerylinkServiceImpl extends MPJBaseServiceImpl<CpCalllistTriggerQuerylinkMapper, CpCalllistTriggerQuerylink>
    implements CpCalllistTriggerQuerylinkService{

    @Override
    public IPage<TriglinkResVo> queryRuleListTrigger(TriglinkReqVo paras)
    {
        return selectJoinListPage(new Page<>(paras.getPageNum(), paras.getPageSize()),
                TriglinkResVo.class,
                new MPJLambdaWrapper<CpCalllistTriggerQuerylink>()
                        .selectAs("(select dsc from sys_names n where n.tid = 'ACTIVITY.QUERY.METHOD' and n.id = t.method)",TriglinkResVo::getMethoddesc)
                        .selectAs("(select coldesc from cfg_activity_querydatacol c2 where splicecol = t.splicecol)",TriglinkResVo::getColdesc)
                        .selectAll(CpCalllistTriggerQuerylink.class)
                        .eq("triggerid",paras.getTriggerid())
                        .eq("type",paras.getType())
                        .orderByAsc("queryruleid")
        );
    }

    @Override
    public CmdResVo updateQueryRuleTrigger(TriglinkEditVo paras)
    {
        CpCalllistTriggerQuerylink def=new CpCalllistTriggerQuerylink();
        BeanUtils.copyProperties(paras,def);
        int ret=baseMapper.updateById(def);
        return new CmdResVo(ret,def.getQueryruleid().toString());
    }

    @Override
    public CmdResVo insertQueryRuleTrigger(TriglinkEditVo paras)
    {
        CpCalllistTriggerQuerylink def=new CpCalllistTriggerQuerylink();
        BeanUtils.copyProperties(paras,def);
        int ret=baseMapper.insert(def);
        return new CmdResVo(ret,def.getQueryruleid().toString());
    }

    @Override
    public CmdResVo deleteQueryRuleTrigger(int id)
    {
        int ret=baseMapper.deleteById(id);
        return new CmdResVo(ret,Integer.toString(id));
    }

}




